/**
 * Created by fkjslee on 2018/4/20.
 */


var serverUrl = "http://118.24.119.103:8081";
// var serverUrl = "http://127.0.0.1:8081";
var HTTP = "http://";

$(function () {
    var loginAndRegister = $('#loginAndRegister').dialog({
        closable: false,
        modal: true,
        buttons: [{
            text: '注册',
            handler: function () {
                var account = document.getElementById("account_register").value;
                var password = document.getElementById("password_register").value;
                var password_repeat = document.getElementById("password_register_repeat").value;
                if (password !== password_repeat) {
                    $.messager.show({
                        title: "注册结果",
                        msg: "两次输入密码不一样, 请确认",
                        type: "show"
                    });
                    return;
                }
                var request = new XMLHttpRequest();
                request.open("POST", HTTP + window.location.host + "/registerAccount?account=" + account + "&password=" + password);
                request.send();
                request.onreadystatechange = function () {
                    if (request.readyState === 4 && request.status === 200) {
                        var json = JSON.parse(request.responseText);
                        if (json.code === "0") {
                            $.messager.show({
                                title: "注册结果",
                                msg: "注册成功",
                                type: "show"
                            })
                        } else {
                            $.messager.show({
                                title: "登录结果",
                                msg: "账户名已存在",
                                type: "show"
                            })
                        }
                    }
                }
            }
        }
        ]
    });
});
